Vuetify is a popular UI framework for Vue apps.
In this article, we’ll look at how to work with the Vuetify framework.
Floating Toolbar with Search
We can add a floating toolbar easily with Vuetify.
For example, we can write:
<template>
<v-container>
<v-row class="text-center">
<v-col col="12">
<v-card
class="pa-4"
flat
height="300px"
img="https://cdn.vuetifyjs.com/images/toolbar/map.jpg"
>
<v-toolbar dense floating>
<v-text-field hide-details single-line></v-text-field>
<v-btn icon>
<v-icon>mdi-dots-vertical</v-icon>
</v-btn>
</v-toolbar>
</v-card>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({}),
};
</script>
We add the v-toolbar in a v-card .
The img prop has the URL of the background image as its value.
The floating prop will make it float on top of the card.
Contextual Action Bars
We can add the contextual action bar that changes when some action is taken.
For example, we can write:
<template>
<v-container>
<v-row class="text-center">
<v-col col="12">
<v-card max-width="500" class="mx-auto">
<v-toolbar :color="selection.length ? 'grey darken-4' : 'deep-purple accent-4'" dark>
<v-app-bar-nav-icon v-if="!selection.length"></v-app-bar-nav-icon>
<v-btn v-else icon @click="selection = []">
<v-icon>mdi-close</v-icon>
</v-btn>
<v-toolbar-title>{{ selection.length ? `${selection.length} selected` : 'App' }}</v-toolbar-title>
<v-spacer></v-spacer>
<v-scale-transition>
<v-btn v-if="selection.length" key="export" icon>
<v-icon>mdi-export-variant</v-icon>
</v-btn>
</v-scale-transition>
<v-scale-transition>
<v-btn v-if="selection.length" key="delete" icon>
<v-icon>mdi-delete</v-icon>
</v-btn>
</v-scale-transition>
<v-btn icon>
<v-icon>mdi-dots-vertical</v-icon>
</v-btn>
</v-toolbar>
<v-card-text>
<v-select v-model="selection" :items="items" multiple label="Select an option"></v-select>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
items: ["apple", "orange", "grape"],
selection: []
}),
};
</script>
We have the v-scale-transiton component that changes with the selection state.
The selection state is controlled by the v-select component.
We also set the v-toolbar-title text with the selection change.
Also, we change the color prop when the selection changes.
So when we select items from the dropdown, the toolbar will change.
System Bars
A system bar is another kind of toolbar.
It looks like the system bar on an Android phone.
To add one, we use the v-system-bar component:
<template>
<v-container>
<v-row class="text-center">
<v-col col="12">
<v-system-bar dark color="primary">
<v-spacer></v-spacer>
<v-icon>mdi-wifi-strength-5</v-icon>
<v-icon>mdi-signal-cellular-outline</v-icon>
<v-icon>mdi-battery</v-icon>
<span>12:30</span>
</v-system-bar>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({}),
};
</script>
We add a v-system-bar component with some icons inside.
Conclusion
We can add a system bar with some icons and text inside.
Also, we can make the toolbar change when its state changes.